<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

define('IMG_TEAMPIC_W', 80);
define('IMG_TEAMPIC_H', 40);
define('LEFT_BANNER_W', 125);
define('RIGHT_BANNER_W', 320);
define('TOP_RANKS_PER_PAGE',10);

define('USER_TOP_RANK_W',30);
define('USER_TOP_RANK_H',30);
define('PRIZE_TOP_RANK_W',60);
define('PRIZE_TOP_RANK_H',40);

// ------------------------------------------------------------------------

function loadCX(){
	return "<img src='".site_url()."cx.png"."' style='margin-bottom:-4px;'/>";
}

function thumb($src, $w='', $h='', $rz = false){
	if(!$w){
		$cond = "h=$h&zc=1";
	}elseif(!$h){
		$cond = "w=$w&zc=1";
	}else{
		$cond = "w=$w&h=$h&zc=1";
	}
	$sExtension = strtolower ( substr( $src, ( strrpos($src, '.') + 1 ) ) );
	if($sExtension == 'gif'){
		$src = site_url(). substr($src,1,strlen($src));
		if($rz){
			$width = ($w != '') ? "width='$w'":'';
			$height = ($h != '') ? "height='$h'":'';
		}else{
			$width = '';
			$height = '';
		}
		return "<img src='$src' $width $height />";
	} 
	return "<img src='".site_url()."uploads/timthumb.php?$cond&src=$src"."' />";
}

function thumb2($src, $w='', $h=''){
	if(!$w){
		$cond = "h=$h&zc=1";
	}elseif(!$h){
		$cond = "w=$w&zc=1";
	}else{
		$cond = "w=$w&h=$h&zc=1";
	}
	$sExtension = strtolower ( substr( $src, ( strrpos($src, '.') + 1 ) ) );
	if($sExtension == 'gif'){
		$src = site_url(). substr($src,1,strlen($src));
		return $src;
	} 
	return site_url()."uploads/timthumb.php?$cond&src=$src" ;
}

function loader_image($ext=""){
	return "&nbsp;&nbsp;<img $ext src='".site_url()."addons/default/themes/clicxa/css/images/ajax-loader.gif"."' />";
}

function vs_image($ext=""){
	return "<img src='".site_url()."addons/default/themes/clicxa/img/vs.png'" ."$ext />";
}


function getImagesFromArticle($article, $mode="ONE"){
	$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $article, $matches);
	if($mode == "ONE"){
		return $matches[1][0];
	}else{
		return $matches[1];
	}	
}

function getRankIcon($rank, $tournament_id, $ext,$w=0,$h=0){
	$ci = & get_instance();
	$prizeListArray = $ci->prize_entity->getArrayListOfPrize($tournament_id);
	$prizeId = 0;
	
	$w= ($w==0) ? 70:$w;
	$h= ($h==0) ? 50:$h;
	
	foreach($prizeListArray as $item){
		if($item->rank == $rank){
			$prizeId = $item->id;
			break;
		}
	}
	if($prizeId == 0){
		return "";
	}
	$PRIZE = $ci->prize_entity->init('id',$prizeId);
	$pimage = $PRIZE->getPrizeImage();
	return "<img src='".thumb2($pimage,PRIZE_TOP_RANK_W,PRIZE_TOP_RANK_H)."' $ext />"; 
}


function getRankImage($rank, $tournament_id, $ext){
	$ci = & get_instance();
	$prizeListArray = $ci->prize_entity->getArrayListOfPrize($tournament_id);
	$prizeId = 0;
	
	foreach($prizeListArray as $item){
		if($item->rank == $rank){
			$prizeId = $item->id;
			break;
		}
	}
	if($prizeId == 0){
		return "";
	}
	$PRIZE = $ci->prize_entity->init('id',$prizeId);
	$pimage = $PRIZE->getPrizeImage();
	return "<img src='".thumb2($pimage,200,100)."' $ext />"; 
}